	import moveView from '/reading/components/moveView.vue'
export default {
	components:{
		moveView
	},
	data() {
		return {
			searchKey: '',
			searchList: [],
			list: [],
			isSearch: false,

			history: uni.getStorageSync("searchHistory"),

		}
	},
	onLoad() {
		uni.setNavigationBarTitle({
			title: "搜索"
		});



	},
	onShow() {

	},
	methods: {
		tagAction(title) {
			this.searchKey = title;
			this.$refs.paging.reload();
		},
		queryList() {
			this.search();
		},
		search() {

			if (!this.searchKey || this.searchKey.length == 0) {
				this.$refs.paging.complete([]);
				return;
			}
			this.isSearch = true;
			uni.showLoading({
				title: '搜索中'
			});
			if (this.history.indexOf(this.searchKey) == -1) {
				if (!this.history || this.history.length == 0) {
					this.history = [];
				}
				this.history.unshift(this.searchKey);
				if (this.history.length > 15) {
					this.history.pop()
				}
				uni.setStorage({
					key: "searchHistory",
					data: this.history
				})
			}



			uniCloud.callFunction({
				name: 'router',
				data: {
					action: 'book/searchBqg',
					data: {
						searchKey: this.searchKey,
					}
				}
			}).then(res => {
				uni.hideLoading();
				// this.searchList = res.result;
				this.$refs.paging.complete(res.result);
			}).catch((err) => {
				uni.hideLoading();
			})

		},

		selectItem(index) {
			var model = this.searchList[index];
			uni.navigateTo({

				url: `/reading/pages/read/index?title=${model.title}&url=${encodeURIComponent(model.link)}`
			});
		}
	}
}